from Common.Client import Client
from Controller.BaseController import BaseController
from Utility import ParameterKey
from django.utils import simplejson

class GetCampaignController(BaseController):
    def get(self):
        """
        Load Campaign by client ID
        Return JSON string
        It take a query string "hpid"
        """
        client_id = self.request.get(ParameterKey.CLIENT_ID)
        client = Client.get(client_id)
        campaigns = []
        for campaign in client.Campaigns:
            campaignJson = {}
            campaignJson['CampaignKey'] = str(campaign.key())
            campaignJson['CampaignName'] = campaign.CampaignName
            campaigns.append(campaignJson)
        self.response.out.write(simplejson.dumps(campaigns))